home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 363 / xprolog2 / nrev < prev    next >
Text File  |  1985-11-19  |  593b  |  29 lines

  1. /* Naive Reverse Benchmark    */
  2.  
  3. nrev:- write('list length: '),
  4.     read(X),
  5.     conslist(X, List),
  6.     T1 is cputime,
  7.     nreverse(List, R),
  8.     T2 is cputime,
  9.     T is T2 - T1,
  10.     I is (X*(X+3))/2 + 1,
  11.     LIPS is (I*1000)/T,
  12.     write('LIPS= '),
  13.     write(LIPS),
  14.     write(' in '), write(T), write(' msec.'),
  15.     nl,!.
  16.     
  17. nreverse([], []).
  18. nreverse([X|L0],L) :- nreverse(L0, L1),
  19.     concat(L1, [X], L).
  20.  
  21. conslist(0, []) :- !.
  22. conslist(N, [N|L]) :-
  23.     N1 is N-1,
  24.     conslist(N1, L).
  25.  
  26. concat([],L,L).                % common append procedure
  27. concat([X|L1],L2,[X|L3]) :- concat(L1,L2,L3).
  28.  
  29.